<?php

class M{

    private $vars = array();

    public function __set($index,$value){
        $this->vars[$index] = $value;
    
    }

    public function __get($index){
        return $this->vars[$index];

    }

}

class M_router{
    
    public $M;

    public function __construct($M){
        $this->M = $M;
    }

    public function loader(){
        //url route
        $url_params = explode('/',substr($_SERVER['REQUEST_URI'],1));
        $_controller = ($url_params[2])?$url_params[2]:'Mindex';
        $_action = ($url_params[3])?$url_params[3]:'index';
        $params = array_slice($url_params,4);

        //load mod
        if(!is_file(S_ROOT.DS.'application/controllers/'.$_controller.'.php')){
            die($_controller.'.php not found!');
        }

        require_once(S_ROOT.DS.'application/controllers/'.$_controller.'.php');
        
        $controller = new $_controller($this->M);
        if(method_exists($controller,$_action)){
            call_user_func_array(array($controller,$_action),$params);
        }else{
            die(" {$_action} not found");
        }
        //$controller->$_action();
        //call_user_func(array($_controller.'_controller',$_action));

    }
}

class M_template{
    
    public $M;

    public function __construct($M){
        $this->M = $M;

    }

    public function view($layout,$data){
        extract($data);
        if(is_file(S_ROOT.DS.'application/views/'.$layout.'.tpl.htm')){
            require(S_ROOT.DS.'application/views/'.$layout.'.tpl.htm');
        }else{
            die("<B>{$layout}.tpl.htm</B> is not found");
        }

    }
}

Abstract class MC{
    public $M;
    public function __construct($M){
        $this->M = $M;

    }
}

abstract class MM{
   public $M;
   public function __construct($M){
        $this->M = $M;
   }
}

?>
